home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / mblib10.zip / MB_LIB.H < prev    next >
C/C++ Source or Header  |  1993-01-03  |  17KB  |  294 lines

  1. /***************************************************************************\
  2. *             MSGBASE.H - Message base header file                          *
  3. *****************************************************************************
  4. *                                                                           *
  5. *                     MB_lib (MsgBase library) V1.00                        *
  6. *            (Hudson message base access / manipulation routines)           *
  7. *                                                                           *
  8. *      This C version (c) F.W. van Wensveen 1993. All rights reserved.      *
  9. *  Original Pascal source code (c) Richard Faasen and In Fase productions,  *
  10. *                             The Netherlands.                              *
  11. *                                                                           *
  12. *                       First revision: 17/08/1992                          *
  13. *                                                                           *
  14. \***************************************************************************/
  15.  
  16.  
  17. /* First, a C++ fixup ******************************************************/
  18.  
  19. #ifndef __MB_LIB_H
  20. #define __MB_LIB_H
  21.  
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26.  
  27. /* Includes and defines ****************************************************/
  28.  
  29. #include <dir.h>
  30.  
  31. #define HCR    0x0D                    /* Hard carriage return             */
  32. #define SCR    0x8D                    /* Soft carriage return             */
  33. #define LF     0x0A                    /* Line feed                        */
  34. #define KLUDGE 0x01                    /* Kludge denominator               */
  35. #define BELL   0x07                    /* Bell character / ring a ding     */
  36.  
  37. #define NOKLUDGES 0x00                 /* txt_dump shouldn't dump kludges  */
  38. #define KLUDGES   0x01                 /* txt_dump should dump kludges     */
  39.  
  40. /* Critical errors */
  41. #define NOT_ERR 0x00                   /* No error                         */
  42. #define MEM_ERR 0x01                   /* Memory error - out of memory     */
  43. #define FRD_ERR 0x02                   /* File read error                  */
  44. #define FWR_ERR 0x03                   /* File write error                 */
  45. #define FCR_ERR 0x04                   /* File create error                */
  46. #define MNO_ERR 0x05                   /* Message base not open error      */
  47. #define IRN_ERR 0x06                   /* Invalid record no., out of bound */
  48. #define MBC_ERR 0x07                   /* Msg base corrupt                 */
  49.  
  50. #define MA_DELETED      0x01           /* Message attributes               */
  51. #define MA_UNSENT       0X02
  52. #define MA_NETMAIL      0X04
  53. #define MA_PRIVATE      0X08
  54. #define MA_RECEIVED     0X10
  55. #define MA_UNMOVED      0X20
  56. #define MA_LOCAL        0X40
  57.  
  58. #define NA_KILL         0X01           /* Hudson netmail attributes        */
  59. #define NA_SENT         0X02
  60. #define NA_FILE         0X04
  61. #define NA_CRASH        0X08
  62. #define NA_RECEIPT      0X10
  63. #define NA_AUDIT        0X20
  64. #define NA_RETURN       0X40
  65.  
  66. #define NM_PRIVATE      0X0001         /* Opus (*.MSG) Netmail attributes   */
  67. #define NM_CRASH        0x0002
  68. #define NM_RECEIVED     0x0004
  69. #define NM_SENT         0x0008
  70. #define NM_FILE         0x0010
  71. #define NM_TRANSIT      0x0020
  72. #define NM_ORPHAN       0x0040
  73. #define NM_KILL         0x0080
  74. #define NM_LOCAL        0x0100
  75. #define NM_HOLD         0x0200
  76. #define NM_UNUSED       0x4000
  77. #define NM_REQUEST      0x0800
  78. #define NM_RECEIPT      0x1000
  79. #define NM_ISRECEIPT    0x2000
  80. #define NM_AUDIT        0x4000
  81. #define NM_UPDATEREQ    0x8000
  82.  
  83.  
  84. /**************************** C A U T I O N ********************************/
  85. /* The strings in the Hudson message base files are all Pascal convention  */
  86. /* strings - a length byte followed by the actual characters.              */
  87. /* I have attempted to maintain this format by defining the strings as a   */
  88. /* structure containing a length byte and a character array, but this      */
  89. /* lead to too much trouble from the programmers point of view. So the     */
  90. /* strings in the following structure are just defined as arrays of chars. */
  91. /* They may only be read from and written to disk using the read and write */
  92. /* functions in this library, which convert the string formats from Pascal */
  93. /* to C format and vice versa. THEY MAY NOT BE READ AND WRITTEN DIRECTLY!! */
  94. /* Writing structures to the message base by any other means than the      */
  95. /* functions provided therefore will cause corruption of the message base. */
  96. /***************************************************************************/
  97.  
  98. typedef struct {                       /* MSGINFO.BBS structure definition */
  99.   unsigned int low_msg;                /* Lowest msg # in message base     */
  100.   unsigned int high_msg;               /* Highest msg # in message base    */
  101.   unsigned int total_msgs;             /* Total # of messages in base      */
  102.   unsigned int total_on_board [200];   /* Number of messages / board       */
  103. } MSGINFO_RECORD;
  104.  
  105. typedef struct {                       /* MSGIDX.BBS structure definiton   */
  106.   int msg_num;                         /* Message #                        */
  107.   unsigned char board;                 /* Board # where msg is stored      */
  108. } MSGIDX_RECORD;
  109.  
  110. typedef char MSGTOIDX_RECORD [36];     /* MSGTOIDX.BBS structure def.      */
  111.  
  112. typedef struct {                       /* MSGHDR.BBS structure definition  */
  113.   int msgnum;                          /* Message number                   */
  114.   unsigned int prev_reply;             /* Msg # of previous reply, 0 if no */
  115.   unsigned int next_reply;             /* Msg # of next reply, 0 if none   */
  116.   unsigned int times_read;             /* # of times msg was read, UNUSED  */
  117.   unsigned int start_block;            /* Record # of msg in MSGTXT.BBS    */
  118.   unsigned int num_blocks;             /* # of records in MSGTXT.BBS       */
  119.   unsigned int dest_net;               /* Destination net                  */
  120.   unsigned int dest_node;              /* Destination node                 */
  121.   unsigned int orig_net;               /* Origin net                       */
  122.   unsigned int orig_node;              /* Origin node                      */
  123.   unsigned char dest_zone;             /* Destination zone                 */
  124.   unsigned char orig_zone;             /* Origin zone                      */
  125.   unsigned int cost;                   /* Cost (Netmail)                   */
  126.   unsigned char msg_attr;              /* Msg attributes. Bits as follows: */
  127.                                        /* 0 : Deleted                      */
  128.                                        /* 1 : Unsent                       */
  129.                                        /* 2 : Netmail                      */
  130.                                        /* 3 : Private                      */
  131.                                        /* 4 : Received                     */
  132.                                        /* 5 : Unmoved outgoing echo        */
  133.                                        /* 6 : Local                        */
  134.                                        /* 7 : RESERVED                     */
  135.   unsigned char net_attr;              /* Netmail attributes. Bits follow: */
  136.                                        /* 0 : Kill/Sent                    */
  137.                                        /* 1 : Sent                         */
  138.                                        /* 2 : File attach                  */
  139.                                        /* 3 : Crash                        */
  140.                                        /* 4 : Receipt request              */
  141.                                        /* 5 : Audit request                */
  142.                                        /* 6 : Is a return receipt          */
  143.                                        /* 7 : RESERVED                     */
  144.   unsigned char board;                 /* Message board #                  */
  145.   char post_time [6];                  /* Time message was posted          */
  146.   char post_date [9];                  /* Date message was posted          */
  147.   char who_to [36];                    /* Recipient to whom msg is sent    */
  148.   char who_from [36];                  /* Sender who posted message        */
  149.   char subject [73];                   /* Subject line of message          */
  150. } MSGHDR_RECORD;
  151.  
  152. typedef struct {                       /* MSGTXT.BBS structure definition  */
  153.   unsigned char str_len;               /* This string is stored in memory  */
  154.   char str_txt [255];                  /*  in Pascal format to reduce      */
  155. } MSGTXT_RECORD;                       /*  overhead, so take care!         */
  156.  
  157.  
  158. /* The strings in the *.MSG file header (Opus style) aren't Pascal type    */
  159. /* strings but have the 'normal' ASCIIZ  format.                           */
  160.  
  161. typedef struct {                       /* OPUS-style (*.MSG) msg format    */
  162.   char who_from [36];                  /* Sender who posted message        */
  163.   char who_to [36];                    /* Recipient  to whom msg is sent   */
  164.   char subject [72];                   /* Subject line of message          */
  165.   char datetime [20];                  /* Date/time msg was last edited    */
  166.   unsigned int times_read;             /* # of times message was read      */
  167.   unsigned int dest_node;              /* Destination node                 */
  168.   unsigned int orig_node;              /* Origin node                      */
  169.   unsigned int cost;                   /* Cost to send netmail msg         */
  170.   unsigned int orig_net;               /* Origin net                       */
  171.   unsigned int dest_net;               /* Destination net                  */
  172.   unsigned int dest_zone;              /* Destination zone  (These fields) */
  173.   unsigned int orig_zone;              /* Origin zone       (were padded ) */
  174.   unsigned int dest_point;             /* Destination point (with 8 0's  ) */
  175.   unsigned int orig_point;             /* Origin point      (in FSC-0001 ) */
  176.   unsigned int reply_to;               /* Msg # to which this one replies  */
  177.   unsigned int attribute;              /* Msg attributes. Bits as follows: */
  178.                                        /* 0  : Private                     */
  179.                                        /* 1  : Crash                       */
  180.                                        /* 2  : Received                    */
  181.                                        /* 3  : Sent                        */
  182.                                        /* 4  : File attached               */
  183.                                        /* 5  : In transit                  */
  184.                                        /* 6  : Orphan                      */
  185.                                        /* 7  : Kill when sent              */
  186.                                        /* 8  : Locak                       */
  187.                                        /* 9  : Hold for pickup             */
  188.                                        /* 10 : UNUSED                      */
  189.                                        /* 11 : File request                */
  190.                                        /* 12 : Return receipt request      */
  191.                                        /* 13 : Is a return receipt         */
  192.                                        /* 14 : Audit request               */
  193.                                        /* 15 : File update request         */
  194.   unsigned int next_reply;             /* Next msg in reply chain          */
  195. } NET_RECORD;
  196.  
  197. /* Message text is stored as follows: a linked list of records contains    */
  198. /* pointers to a MSGTXT record. This record contains 255 bytes of message  */
  199. /* text. This Message Text Block List (MTBL) can be changed at will.       */
  200. /* Because the programmer won't work with the 'raw' message text in RAM    */
  201. /* directly, the string format of the message text is *not* converted. The */
  202. /* text blocks contain the strings in Pascal format.                       */
  203.  
  204. typedef struct __mtbl__ {              /* Element of Msg Text Block List   */
  205.   MSGTXT_RECORD * txt;                 /* Pointer to text block            */
  206.   struct __mtbl__ * next;              /* Pointer to next struct in list   */
  207. } MTBL;
  208.  
  209. typedef MTBL * M_TEXT;                 /* Text handle - ptr to MTBL start  */
  210.  
  211.  
  212. /* Public data *************************************************************/
  213.  
  214. extern MSGINFO_RECORD msginfo;         /* Global MSGINFO record            */
  215. extern int _Cdecl errortype;           /* Indicate type of error occurred  */
  216. extern char _Cdecl errorstring [];     /* Printable string with error msg. */
  217.  
  218.  
  219. /* Macro's and prototypes **************************************************/
  220.  
  221. /* Manipulating message text in memory */
  222. M_TEXT        txt_new (char *);                  /* Create new text        */
  223. int           txt_add (M_TEXT, char *);          /* Add a line of text     */
  224. void          txt_dispose (M_TEXT);              /* Dispose of text        */
  225. int           txt_dump (M_TEXT, int (*) (char *), unsigned char,
  226.             unsigned char);          /* Dump message text      */
  227.  
  228. /* Message base file access */
  229. int           msg_open (char *);                 /* Open message base      */
  230. void          msg_close (void);                  /* Close message base     */
  231.  
  232. /* Message base file locking */
  233. int           msg_lock (char *);                 /* Lock message base      */
  234. void          msg_unlock (void);                 /* Unlock message base    */
  235.  
  236. /* Reading message base */
  237. int           msg_read_info (void);                   /* Read MSGINFO.BBS  */
  238. int           msg_read_hdr (long, MSGHDR_RECORD *);   /* Read MSGHDR.BBS   */
  239. int           msg_read_idx (long, MSGIDX_RECORD *);   /* Read MSGIDX.BBS   */
  240. int           msg_read_toidx (long, MSGTOIDX_RECORD *);   /* The same with */
  241. M_TEXT        msg_read_text (MSGHDR_RECORD *);   /* Read text 4 spec'd msg */
  242.  
  243. /* Writing message base */
  244. int           msg_write_info (void);                  /* Write MSGINFO.BBS */
  245. int           msg_write_hdr (long, MSGHDR_RECORD *);  /* Write MSGHDR.BBS  */
  246. int           msg_write_idx (long, MSGIDX_RECORD *);  /* Write MSGIDX.BBS  */
  247. int           msg_write_toidx (long, MSGTOIDX_RECORD *);  /* MSGTOIDX.BBS  */
  248. int           msg_write_text (MSGHDR_RECORD *, M_TEXT);  /* New/change txt */
  249. int           msg_write_new (MSGHDR_RECORD *, M_TEXT);    /* Write new msg */
  250. int           msg_kill (long);                            /* Kill message  */
  251.  
  252. /* Message manipulation support routines */
  253. long          msg_msgnr2recnr (unsigned int);    /* Convert msg # to rec # */
  254. unsigned int  msg_recnr2msgnr (long);            /* Convert rec # to msg # */
  255. void          msg_hdr_clear (MSGHDR_RECORD *);   /* Clear header record    */
  256. int           msg_fixup4d (MSGHDR_RECORD *, M_TEXT);  /* hdr -> @INTL      */
  257.  
  258. /* Message base search routines */
  259. long          msg_firstinboard (unsigned char); /* Get # of 1st msg in brd */
  260. long          msg_lastinboard (unsigned char);   /* Get # of last msg in b.*/
  261. long          msg_nextinboard (long);            /* Get # of next msg in b.*/
  262. long          msg_previnboard (long);            /* Get # of prev msg in b.*/
  263. long          msg_firstto (MSGTOIDX_RECORD *);   /* Get # of 1st msg to..  */
  264. long          msg_lastto (MSGTOIDX_RECORD *);    /* Get # of last msg to.. */
  265. long          msg_nextto (long);                 /* Get # of next msg to.. */
  266. long          msg_prevto (long);                 /* Get # of prev msg to.. */
  267.  
  268. /* Netmail search and manipulation support routines */
  269. int           net_first (char *);                /* Get # of first net msg */
  270. int           net_last (char *);                 /* Get # of last net msg  */
  271. int           net_next (char *, int);            /* Get # of next net msg  */
  272. int           net_prev (char *, int);            /* Get # of prev net msg  */
  273. void          net_hdr_clear (NET_RECORD *);      /* Clear a netmail header */
  274. int           net_fixup4d (NET_RECORD *, M_TEXT);     /* INTL/FMPT/TOPT    */
  275. int           net_getlastread (char *);          /* Get *.MSG lastread ptr */
  276. int           net_setlastread (char *, int);     /* Set *.MSG lastread ptr */
  277.  
  278. /* Reading and writing netmail */
  279. int           net_read_hdr (char *, int, NET_RECORD *);   /* Read net. hdr */
  280. M_TEXT        net_read_text (char *, int);       /* Read netmail text      */
  281. int           net_write (char *, int, NET_RECORD *, M_TEXT); /* Write net. */
  282. int           net_kill (char *, int);            /* Kill *.MSG netmail msg */
  283.  
  284.  
  285. /* Wrap up the C++ fixup ***************************************************/
  286.  
  287. #ifdef __cplusplus
  288. }
  289. #endif
  290. #endif   /* __MB_LIB_H */
  291.  
  292.  
  293. /* EOF */
  294.